﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:clr="clr-namespace:System;assembly=mscorlib" 
                    xmlns:clr2="clr-namespace:System.Collections;assembly=mscorlib" 
                    xmlns:generics="clr-namespace:System.Collections.Generic;assembly=mscorlib"
                    xmlns:local="clr-namespace:WPG"                     
                    xmlns:data="clr-namespace:WPG.Data" 
                    xmlns:converters="clr-namespace:WPG.Converters" 
                    xmlns:typeeditors="clr-namespace:WPG.TypeEditors" 
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2006" 
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:TypeEditors="clr-namespace:WPG.Themes.TypeEditors">

	<DataTemplate DataType="{x:Type data:PropertyCollection}">
		<ItemsControl ItemsSource="{Binding Path=Items}" />
	</DataTemplate>

	<DataTemplate DataType="{x:Type data:PropertyCategory}">
		<Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ExpanderStyle}}" Header="{Binding Category}" IsExpanded="True" Background="LightGray">
			<ItemsControl ItemsSource="{Binding Path=Items}" />
		</Expander>
	</DataTemplate>

	<DataTemplate DataType="{x:Type data:ExpandableProperty}">
		<Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ExpanderStyle}}" Header="{Binding Name}" IsExpanded="False" Background="LightGray">
			<ItemsControl ItemsSource="{Binding Path=Items}" />
		</Expander>
	</DataTemplate>

	<local:PropertyTemplateSelector x:Key="propertyTemplateSelector" />


	<DataTemplate DataType="{x:Type data:Property}">
		<DockPanel Height="20" Margin="0 -1 0 0">
			<Border BorderThickness="1 1 0 1" BorderBrush="LightGray">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="{Binding NameWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PropertyGrid}}}"></ColumnDefinition>
						<ColumnDefinition></ColumnDefinition>
					</Grid.ColumnDefinitions>
					<TextBlock Grid.Column="0" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}" DockPanel.Dock="Left" Margin="0,0,2,0" TextAlignment="Left" VerticalAlignment="Center" Text="{Binding Mode=OneTime, Path=Name}">
						<TextBlock.ToolTip>
							<ToolTip>
								<ToolTip.Content>
									<StackPanel>
										<StackPanel Orientation="Horizontal">
											<TextBlock Text="{Binding Mode=OneTime, Path=Name}" Padding="1 0 0 0" />
											<TextBlock Text=": " Padding="1 0 0 0" />
											<TextBlock Text="{Binding Mode=OneTime, Path=PropertyType}" FontWeight="Bold" Padding="1 0 0 0" />
										</StackPanel>
										<TextBlock Text="{Binding Mode=OneTime, Path=Description}" Padding="1 1 0 0" />
									</StackPanel>
								</ToolTip.Content>
							</ToolTip>
						</TextBlock.ToolTip>
					</TextBlock>
					<Border Grid.Column="1" Margin="0" Padding="0" BorderThickness="2 0 0 0" BorderBrush="LightGray">
						<ContentControl VerticalAlignment="Center" Content="{Binding Mode=OneWay}" ContentTemplateSelector="{StaticResource propertyTemplateSelector}" />
					</Border>
				</Grid>
			</Border>
		</DockPanel>
	</DataTemplate>


	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=default}">
		<TextBox IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBoxStyle}}">
			<TextBox.Text>
				<Binding Mode="TwoWay" Path="Value">
					<Binding.ValidationRules>
						<ExceptionValidationRule />
					</Binding.ValidationRules>
				</Binding>
			</TextBox.Text>
		</TextBox>
	</DataTemplate>
    
    
    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type generics:List`1[System.Object]}}">
        <TypeEditors:CollectionEditorControl NumerableType="{Binding Path=PropertyType}" NumerableValue="{Binding Path=Value}" MyProperty="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TypeEditors:CollectionEditorControl>        
    </DataTemplate>
      
    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type Brush}}">
        <TypeEditors:BrushEditorControl Brush="{Binding Path=Value}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TypeEditors:BrushEditorControl>
    </DataTemplate>
    
    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Int32}}">
        <typeeditors:IntegerTypeEditor Text="{Binding Path=Value,UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding Path=IsReadOnly}" Foreground="Black"></typeeditors:IntegerTypeEditor>
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Boolean}}">
		<CheckBox Margin="2 0 0 0" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=CheckBoxStyle}}" IsEnabled="{Binding Path=IsWriteable}" IsChecked="{Binding Path=Value}" />
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr2:IList}}">
		<ListBox ItemsSource="{Binding Path=Value}" />
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Enum}}">
		<ComboBox Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ComboBoxStyle}}" SelectedValue="{Binding Path=Value}">
			<ComboBox.ItemsSource>
				<Binding Path="Value">
					<Binding.Converter>
						<converters:EnumTypeConverter />
					</Binding.Converter>
				</Binding>
			</ComboBox.ItemsSource>
		</ComboBox>
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Double}}">
		<TextBox IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBoxStyle}}">
			<TextBox.Text>
				<Binding Mode="TwoWay" Path="Value">
					<Binding.Converter>
						<converters:DoubleTypeConverter />
					</Binding.Converter>
				</Binding>
			</TextBox.Text>
		</TextBox>
	</DataTemplate>

</ResourceDictionary>